<template>
	<view class="content">
		<navbar title='商品管理'>
		</navbar>
		<view class="content">
			<u-sticky offset-top="0">
				<view class="tuanone">
					<view class="souview">
						<image class="icon_sshui" src="@/pages_client/static/img/icon_sshui.png" mode="" />
						<u-input v-model="keywords" type="text" placeholder='搜索商品' @confirm="getClear" />
					</view>
					<!-- <view class="pai">
						<text class="painame">排序</text>
						<image class="paiimg" src="@/pages_client/static/img/icon_jg.png" mode="" />
					</view> -->
					<view class="pai" @click="shaipopshow=true">
						<text class="painame">筛选</text>
						<image class="paiimg" src="@/pages_client/static/img/shai.png" mode="" />
					</view>
					<view class="pai" @click="isguan=!isguan">
						<text class="painame guanname">{{ !isguan?'商品管理':'退出管理' }}</text>
					</view>
				</view>
			</u-sticky>
			<view class="menlist">
				<!-- <view class="nodata">
					<image class="kzt_img_zwsj" src="@/pages_client/static/mine/img_kzt_sp.png" mode="" />
					<text>暂无商品</text>
				</view> -->
				<view class="oitem" v-for="(item,index) in list" :key="index">
					<view class="olist">
						<view class="onav">
							<image v-if="isguan&&item.isselect" class="icon_dz_xz_s" src="@/pages_client/static/img/icon_dz_xz_s.png" @click.stop="getgou(item,index)" />
							<image v-if="isguan&&!item.isselect" class="icon_dz_xz_s" src="@/pages_client/static/img/icon_dz_xz_n.png" @click.stop="getgou(item,index)" />
							<image class="tu" :src="ossThree(item.image)" />
							<view class="navright" :style="{width:isguan?'58%':'68%'}">
								<view class="navone">
									<!-- <text class="tuan">团购</text> -->
									<text class="bt">{{item.title}}</text>
									
								</view>
								<view class="yugu">
									<view class="yuguleft">
										<text class="yuname">原价</text>
										<text class="jia">¥{{ item.oprice }}</text>
									</view>
									<view class="yuguleft">
										<text class="yuname">售价</text>
										<text class="jia">¥{{ item.price }}</text>
									</view>
								</view>
								<!-- <view class="navone">
									<view class="shoujia">售价￥{{ item.price }}</view>
								</view> -->
								
							</view>
						</view>
						
					</view>
					<view class="heview">
						<view class="hename">
							<view class="btn" @click.stop="del(item,index)">删除</view>
							<view class="btn fukuan" @click.stop="zhidin(item)">置顶</view>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" @loadmore="loadmore" />
			</view>
		</view>

		<view class="botview" v-if="isguan">
			<image class="icon_dz_xz_s" v-if="quanbu" @click="getquan" src="@/pages_client/static/img/icon_dz_xz_s.png" />
			<image class="icon_dz_xz_s" v-if="!quanbu" @click="getquan" src="@/pages_client/static/img/icon_dz_xz_n.png" />
			<text class="quan" @click="getquan">全选</text>
			<!-- <text class="nums"><text class="numsed">1</text>/3</text> -->
			<view class="hename" style="margin-left: auto;">
				<view class="btn" @click="dels">删除</view>
				<!-- <view class="btn fukuan">置顶</view> -->
			</view>
		</view>

		<!-- 筛选 -->
		<u-popup  v-model="shaipopshow" mode="bottom" width="100%" ref="auth" :closeable="true" :mask-close-able="true" :custom="true" :mask-click="false" @close="closeshai">
			<view class="shiapop">
				<!-- <view class="shaiview">
					<view class="stit">
						商品类目
					</view>
					<view class="shailist">
						<view class="shaiitem sactive">
							美容养颜
						</view>
						<view class="shaiitem">
							美容养颜
						</view>
						<view class="shaiitem">
							美容养颜
						</view>
						<view class="shaiitem">
							美容养颜
						</view>
					</view>
				</view> -->
				<view class="shaiview">
					<view class="stit">
						商品类目
					</view>
					<view class="shailist">
						<view class="shaiitem " :class="classitem.id==item.id?'sactive':''" v-for="(item,index) in classlist" :key="index"  @click="getcateClick(item)">
							{{item.name}}
						</view>
					</view>
				</view>
				<view class="botzhi">
					<!-- <view class="bzhidin">置顶</view> -->
					<view class="bzhidin que ml" @click="closeshai">确定</view>
				</view>
			</view>

			
		</u-popup>	
	</view>
</template>

<script>
	export default {
		components: {
		},
		data() {
			return {
				value:1,
				name:'',
				isguan:false,
				shaipopshow:false,
				list: [],
				page: 1,
				limit: 10,
				last_page: 1,
				status: "loadmore",
				shop_id:'',
				order:'',//排序
				keywords:'',
				pindex:0,
				quanbu:false,
				classitem:{
					id:''
				},
				classlist:[],
			}
		},
		onLoad(option) {
			if(option.shop_id){
				this.shop_id = option.shop_id
			}
			this.getList()
			this.getcate()
		},
		onShow() {
		},
		onReachBottom: function () {
			this.loadmore();
		},
		methods: {
			async getcate() {
				let res = await this.$u.api.getCate({
				});
				// console.log(res)
				// let data = res
				// let parms = []
				// for (let i in data) {
				// 	let a = {}
				// 	a.value = data[i].id
				// 	a.label = data[i].name
				// 	parms.push(a)
				// }
				this.classlist = res
				// if(this.classitem==''||!this.classitem){
				// 	this.classitem = this.classlist[0]
				// }
			},
			getcateClick(item){
				this.classitem = item
				// console.log(this.classitem)
				this.closeshai()
				this.getClear()
			},
			closeteam(){
				this.teampopshow = false
			},
			change(index) {
				this.current = index;
			},
			getdetail(item){
				this.navrouter('/pages_client/mine/OrderDetail')
			},
			closeshai(){
				this.shaipopshow = false
			},
			async getList(){//列表数据
				let res = await this.$u.api.getGoodsListByShop({
				  limit:this.limit,
				  page:this.page,
				  shop_id:this.shop_id,
				  order:this.order,
				  keywords:this.keywords,
				  cid:this.classitem.id
				});
				this.last_page = res.lastpage
				let list = res.list;
				for(let i in list){
					list[i].isselect = false
				}
				this.list = this.page == 1 ? list : [...this.list, ...list];	
				if(res.list==''||Number(list.length)<Number(this.limit)||Number(this.page)>Number(this.last_page)){
					this.status = 'nomore';
				}
				console.log(this.list)
				
			},
			loadmore() {
				let page = this.page;
				// let last_page = this.last_page;
				if (this.status == 'loadmore') {
					this.page++;
					this.getList();
				}
			},
			getClear(){
				this.list = []
				this.page = 1,
				this.status= "loadmore"
				this.getList()
			},
			async del(item,index){
				this.pindex = index
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除？',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮的文字  
					// showCancel: false, // 是否显示取消按钮，默认为 true
					// confirmColor: '#f55850',
					// cancelColor: '#39B54A',
					success: (res) => {
					if(res.confirm) {  
						that.deltwo(item)
					} else {  
						console.log('cancel') //点击取消之后执行的代码
						}  
					} 
				})
			},
			async deltwo(item){
				let res = await this.$u.api.delShopGoods({
					id:item.id,
					shop_id:this.shop_id
				});
				this.$u.toast("删除成功");
				this.getClear()
			},
			async zhidin(item){
				let res = await this.$u.api.topShopGoods({
					id:item.id,
					shop_id:this.shop_id
				});
				this.$u.toast("操作成功");
				this.getClear()
			},
			getquan(){
				if(!this.quanbu){
					let list = this.list
					for(let i in list){
						list[i].isselect = true
					}
					this.quanbu = true
					this.list = list
				}else{
					let list = this.list
					for(let i in list){
						list[i].isselect = false
					}
					this.quanbu = false
					this.list = list
				}
				console.log(this.list)
				this.$forceUpdate()
				
			},
			getgou(item,index){
				let list = this.list
				if(item.isselect){
					list[index].isselect = false
				}else{
					list[index].isselect = true
				}
				this.list = list
				let status = true
				for(let i in list){
					if(!list[i].isselect){
						status=  false
					}
				}
				if(status){
					this.quanbu = true
				}else{
					this.quanbu = false
				}
				console.log(status)
			},
			dels(){
				let list = this.list
				let parms = []
				for(let i in list){
					if(list[i].isselect){
						parms.push(list[i].id)
					}
					
				}
				if(parms==''){
					this.$u.toast("请先勾选商品");
					return;
				}
				let that = this
				uni.showModal({
					title: '提示',
					content: '确定删除？',
					cancelText: "取消", // 取消按钮的文字  
					confirmText: "确认", // 确认按钮的文字  
					// showCancel: false, // 是否显示取消按钮，默认为 true
					// confirmColor: '#f55850',
					// cancelColor: '#39B54A',
					success: (res) => {
					if(res.confirm) {  
						console.log(parms)
						return;
						that.delthree(parms)
					} else {  
						console.log('cancel') //点击取消之后执行的代码
						}  
					} 
				})
			},
			async delthree(parms){
				let res = await this.$u.api.delShopGoodsIds({
					ids:parms.toString(),
					shop_id:this.shop_id
				});
				this.$u.toast("删除成功");
				this.getClear()
			},

		}
	}
</script>

<style lang="scss" scoped>
	page{
		background-color: #f9f9f9;
	}
	.content{
		background-color: #f9f9f9;
		padding-bottom: 130rpx;
		.tuanone{
			background-color: #fff;
			padding: 15rpx 30rpx 20rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			width: 100%;
			.souview{
				display: flex;
				background: #F3F3F3;
				border-radius: 16rpx;
				padding:0 20rpx;
				width: 50%;
				align-items: center;
				margin-right: 20rpx;
				.icon_sshui{
					width: 32rpx;
					height: 32rpx;
					margin-right: 10rpx;
					position: relative;
					top: -3rpx;
				}
			}
			.pai{
				flex: 1;
				display: flex;
				flex-direction: row;
				align-items: center;
				justify-content: center;
				.painame{
					font-weight: bold;
					font-size: 26rpx;
					color: #333333;
				}
				.paiimg{
					width: 40rpx;
					height: 40rpx;
					margin-left: 4rpx;
				}
				.guanname{
					color: #F90101;
				}
			}
			.tuhead{
				max-width: 80%;
				white-space: nowrap;
				.tuitem{
					padding: 8rpx 20rpx;
					background: #F5F5F5;
					border-radius: 10rpx;
					margin-right: 20rpx;
					font-weight: 500;
					font-size: 26rpx;
					color: #333333;
					display: inline-block;
				}
				.tactive{
					background: #52443B;
					color: #fff;
				}
			}
			.icon_tx{
				margin-left: auto;
				width: 40rpx;
				height: 40rpx;
			}
		}	
	}
	.nlist{
		padding: 20rpx;
		display: flex;
		flex-direction: column;
		.nitem{
			padding: 20rpx 25rpx;
			background: #FFFFFF;
			border-radius: 30rpx;
			.nione{
				display: flex;
				flex-direction: row;
				align-items: center;
				.tous{
					width: 81rpx;
					border-radius: 50%;
					height: 81rpx;
					margin-right: 15rpx;
				}
				
				.niright{
					width: 82%;
					display: flex;
					flex-direction: column;
					.rione{
						display: flex;
						flex-direction: row;
						align-items: center;
						.riname{
							max-width: 80%;
							display: inline-block;
							font-weight: bold;
							font-size: 32rpx;
							color: #333333;
						}
						.hyuan{
							width: 80rpx;
							height: 32rpx;
							background: linear-gradient(-90deg, #272727, #4D4D4D);
							border-radius: 6rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							font-weight: 500;
							font-size: 22rpx;
							color: #FFFFFF;
							margin-left: 10rpx;
						}
						.idname{
							font-weight: 400;
							font-size: 24rpx;
							color: #999999;
						}
						.hui{
							margin-left: 40rpx;
						}

					}
					.mttwo{
						margin-top: 15rpx;
					}
				}
				.comm_icon_next{
					margin-left: auto;
					width: 24rpx;
					height: 24rpx;
				}
			}
			.zheview{
				border-top: 1rpx solid #eee;
				display: flex;
				flex-direction: column;
				margin-top: 20rpx;
				padding-top: 20rpx;
				.zheitem{
					display: flex;
					flex-direction: row;
					flex-wrap: wrap;
					.items{
						width: 50%;
						display: flex;
						flex-direction: row;
						align-items: center;
						margin-bottom: 10rpx;
						.ileft{
							font-weight: 500;
							font-size: 24rpx;
							color: #999999;
						}
						.ival{
							font-weight: 500;
							font-size: 26rpx;
							color: #333333;
						}
					}
				}
				.shengbtn{
					display: flex;
					flex-direction: row;
					justify-content: flex-end;
					padding: 0 20rpx 20rpx 0;
					.sbtn{
						padding: 15rpx 25rpx;
						background: #52443B;
						border-radius: 16rpx 16rpx 16rpx 16rpx;
						font-weight: bold;
						font-size: 28rpx;
						color: #FFFFFF;
						margin-left: 20rpx;
					}
				}
			}
		}
	}
	.botview{
		position: fixed;
		height: 120rpx;
		width: 100%;
		bottom: 0;
		background-color: #fff;
		z-index: 10;
		padding: 0 30rpx;
		display: flex;
		align-items: center;
		.icon_dz_xz_s{
			width: 40rpx;
			margin-right: 10rpx;
			height: 40rpx;
		}
		.quan{
			font-weight: 500;
			font-size: 28rpx;
			color: #666666;
		}
		.nums{
			font-weight: 500;
			font-size: 28rpx;
			color: #808080;
			display: inline-block;
			margin-left: 100rpx;
			.numsed{
				font-weight: 500;
				font-size: 28rpx;
				color: #FF7C41;
			}
		}

		.tjia{
			width: 100%;
			height: 90rpx;
			background: #52443B;
			border-radius: 16rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-weight: bold;
			font-size: 28rpx;
			color: #FFFFFF;
		}
	}
	.menlist{
		padding:30rpx 22rpx;
	}
	.oitem{
		display: flex;
		flex-direction: column;
		background: #FFFFFF;
		border-radius: 20rpx;
		margin-bottom: 24rpx;
		padding: 30rpx;
		.ohead{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-bottom: 30rpx;
			.icon_sj{
				width: 30rpx;
				height: 30rpx;
				margin-right: 9rpx;
			}
			.dianname{
				max-width: 70%;
				display: inline-block;
				font-weight: bold;
				font-size: 28rpx;
				color: #272727;
			}
			.zt{
				font-weight: 500;
				font-size: 25rpx;
				color: #FF0050;
			}
		}
		.olist{
			display: flex;
			flex-direction: column;
			.icon_dz_xz_s{
				width: 40rpx;
				margin-right: 20rpx;
				height: 40rpx;
			}
			.onav{
				display: flex;
				flex-direction: row;
				margin-bottom: 20rpx;
				align-items: center;
				.tu{
					width: 180rpx;
					height: 180rpx;
					border-radius: 10rpx;
					margin-right: 20rpx;
				}
				.navright{
					max-width: 68%;
					display: flex;
					flex-direction: column;

					.navone{
						display: flex;
						flex-direction: row;
						margin-bottom: 10rpx;
						.tuan{
							padding: 2rpx 8rpx;
							background: #FF7C41;
							border-radius: 6rpx;
							font-weight: 500;
							font-size: 20rpx;
							color: #FFFFFF;
							margin-right: 10rpx;
						}
						.bt{
							max-width: 100%;
							display: inline-block;
							font-weight: 500;
							font-size: 26rpx;
							color: #222222;
						}
						.btmiao{
							max-width: 80%;
							display: inline-block;
							font-weight: 500;
							font-size: 20rpx;
							color: #BBBBBB;
						}
						.jia{
							font-weight: bold;
							font-size: 26rpx;
							color: #1A1A1A;
						}
						.zheng{
							padding: 4rpx 20rpx;
							border-radius: 6rpx;
							border: 1px solid #999999;
							font-weight: 500;
							font-size: 20rpx;
							color: #999999;
						}
					}
					.navone:last-child{
						margin-bottom: 0;
					}
					.shoujia{
						font-weight: 400;
						font-size: 25rpx;
						display: block;
						margin-top: 8rpx;
						color: #1A1A1A;
					}
					.yugu{
						background: #F9F9F9;
						border-radius: 6rpx;
						display: flex;
						flex-direction: row;
						padding: 8rpx 20rpx;
						flex: 1;
						margin: 5rpx 0;
						
						.yuguleft{
							// flex: 1;
							width: 50%;
							display: flex;
							flex-direction: column;
							justify-content: center;
							align-items: center;
							border-right: 1rpx solid #eee;
							.yuname{
								font-weight: 500;
								font-size: 22rpx;
								color: #BBBBBB;
							}
							.jia{
								font-weight: bold;
								font-size: 30rpx;
								color: #1A1A1A;
								margin-top: 10rpx;
								display: block;
								.jiabai{
									font-weight: 500;
									font-size: 20rpx;
									color: #808080;
									display: inline-block;
									margin-left: 9rpx;
									position: relative;
									top: -2rpx;
								}
								
							}
						}
						.yuguleft:last-child{
							border-right: none;
						}
					}
				}
			}
			.onav:last-child{
				margin-bottom: 0;
			}
			
		}
		.heview{
			display: flex;
			flex-direction: column;
			margin-top: 20rpx;
			
		}
	}
	.hename{
		font-weight: 500;
		font-size: 24rpx;
		color: #666666;
		margin: 13rpx 0;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
	}
	.btn{
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		border-radius: 28rpx;
		border: 1px solid #CCCCCC;
		font-weight: 500;
		font-size: 24rpx;
		color: #1A1A1A;
		margin-left: 20rpx;
		min-width: 140rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.fukuan{
		background: #FF7C41;
		color: #fff;
		border: none;
	}
	.queren{
		background: #483C38;
		color: #fff;
		border: none;
	}
	.nodata{
		margin: 200rpx auto;
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		.kzt_img_zwsj{
			width: 237rpx;
			height: 256rpx;

		}
		text{
			font-weight: 400;
			font-size: 28rpx;
			color: #808080;
			display: block;
			margin-top: 30rpx;
		}
	}
	.shengku{
		font-weight: 500;
		font-size: 28rpx;
		color: #999999;
		display: block;
		margin-top: 8rpx;
	}
	.tablei{
		padding: 10rpx 90rpx 8rpx;
		display: flex;
		flex-direction: row;
		
		.leiitem{
			height: 68rpx;
			background: #F3F3F3;
			border-radius: 34rpx;
			display: flex;
			flex-direction: row;
			width: 100%;
			.tabitem{
				width: 50%;
				height: 100%;
				position: relative;
				display: flex;
				align-items: center;
				justify-content: center;
				font-weight: bold;
				font-size: 32rpx;
				color: #666666;
			}
			.tactive{
				background: #52443B;
				border-radius: 34rpx;
				color: #fff;
			}
		}
	}
	.menitem{
                display: flex;
                flex-direction: row;
                align-items: center;
                background: #FFFFFF;
                border-radius: 24rpx;
                padding: 25rpx;
                margin: 0 30rpx 20rpx;
                .tu{
                    width: 180rpx;
                    height: 180rpx;
                    margin-right: 20rpx;
                    border-radius: 20rpx;
                }
                .menone{
                    display: flex;
                    flex-direction: column;
                    width: 68%;
                    // height: 100%;
                    .menhead{
                        display: flex;
                        flex-direction: row;
                        align-items: center;
                        .name{
                            font-weight: bold;
                            font-size: 32rpx;
                            color: #272727;
                        }
                        .yingye{
                            font-weight: 500;
                            font-size: 26rpx;
                            color: #24B924;
                        }
                        .yingtime{
                            font-weight: 500;
                            font-size: 26rpx;
                            color: #333333;
                            display: inline-block;
                            margin-left: 18rpx;
                        }
                        .icon_dw{
                            width:22rpx;
                            height: 24rpx;
                            margin-right: 8rpx;

                        }
                        .ju{
                            font-weight: 500;
                            font-size: 28rpx;
                            color: #1A1A1A;
                        }
                        .juli{
                            margin-left: 30rpx;
                            font-weight: 500;
                            font-size: 24rpx;
                            color: #999999;
                            display: inline-block;
                            max-width: 70%;
                        }
						.tiview{
							margin-left: auto;
							width: 200rpx;
							height: 68rpx;
							background: #52443B;
							border-radius: 16rpx 16rpx 16rpx 16rpx;
							display: flex;
							align-items: center;
							justify-content: center;
							font-weight: bold;
							font-size: 28rpx;
							color: #FFFFFF;
						}
                    }
                    .mennav{
                        margin-top: 35rpx;
                    }
                }
            }
        // }

		// 筛选弹窗
		.shiapop{
			padding: 30rpx;
			border-radius: 30rpx 30rpx 0 0 ;
			background-color: #fff;
			.stit{
				font-weight: bold;
				font-size: 30rpx;
				color: #333333;
				display: block;
				margin-bottom: 30rpx;
			}
			.shailist{
				display: flex;
				flex-direction: row;
				flex-wrap: wrap;
				.shaiitem{
					padding: 16rpx 20rpx;
					background: #F5F5F5;
					border-radius: 10rpx;
					font-weight: 500;
					font-size: 26rpx;
					color: #333333;
					margin: 0 20rpx 20rpx 0;
				}
				.sactive{
					border: 1px solid #FF7C41;
					background: #FFF2ED;
					color: #FF7C41;
				}
			}
			.shaiview{
				margin-bottom: 40rpx;
			}
			.shaiview:last-child{
				margin-bottom: 0;
			}
			.botzhi{
				display: flex;
				margin-top: 50rpx;
				flex-direction: row;
				align-items: center;
				.bzhidin{
					width: 100%;
					height: 91rpx;
					border-radius: 16rpx;
					border: 1px solid #52443B;
					font-weight: 500;
					font-size: 28rpx;
					color: #52443B;
					display: flex;
					align-items: center;
					justify-content: center;

				}
				.que{
					background: #52443B;
					color: #fff;
				}
			}
		}
</style>
